package org.corolla.cloth.service;

import java.util.List;
import java.util.Set;

import org.corolla.cloth.common.DataBaseHelper;
import org.corolla.cloth.entity.Order;
import org.springframework.stereotype.Service;

@Service("orderService")
public class OrderService {
	
	
	/**
	 * 获取用户参数之后，构造Order
	 * @param clothStyle
	 * @param clothSize
	 * @param clothMount
	 * @param unitPrice
	 * @param totalPriceBySize
	 * @return
	 * @author ZJD
	 */
	public Order generateOrder(String clothStyle,String clothSize,
								int clothMount,double unitPrice,double totalPriceBySize){
		Order order = new Order(clothStyle, clothSize, clothMount, unitPrice, totalPriceBySize);
		return order;
	}
	
	/**
	 * 保存订单
	 * @author ZJD
	 * @param order
	 */
	public void saveOrder(Order order){
		DataBaseHelper.save(order);
		
	}
	
	/**
	 * 付款之后移除订单
	 * @author ZJD
	 * @param order
	 */
	public void removeOrderByPk(int pk){
		DataBaseHelper.removeRecordByPk(pk);
	}
	
	/**
	 * 查询订单
	 * @author ZJD
	 * @param order
	 */
	public Order findOrderByPk(int pk){
		
		return DataBaseHelper.findRecordByPk(pk);
		
	}
	
	/**
	 * 保存多张订单
	 * @author ZJD
	 * @param orders
	 */
	public void saveOrders(Set<Order> orders){
		for(Order order:orders){
			this.saveOrder(order);
		}
	}
	
	/**
	 * 移除多张订单
	 * @param pks 主键的数组
	 */
	public void removeOrdersByPks(int[] pks){		
		for(int i=0;i<pks.length;i++){
			this.removeOrderByPk(pks[i]);
		}
		
	}
	
	/**
	 * 查询多张订单
	 * @param pks 主键的数组
	 */
	public List<Order> findOrdersByPks(int[] pks){
		List<Order> list = DataBaseHelper.findRecordByPks(pks);
		return list;
	}
	
	/**
	 * 查询所有订单
	 * @param pks 主键的数组
	 */
	public List<Order> findAllOrders(){
		List<Order> list = DataBaseHelper.findAllRecords();
		return list;
	}
	
	/**
	 * 查询所有订单
	 * @param pk包含在order中
	 * @param order 修改过的订单
	 */
	public void upadteCountByPk(Order order){
		DataBaseHelper.upadteRecordByPk(order);
	}
	
	

}
